﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ListViewDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class FListViewDemo : Window
    {
        // 根节点集合（绑定到TreeView的ItemsSource）
        private ObservableCollection<itemDemo> tListItem { get; }=new ObservableCollection<itemDemo>();
        public FListViewDemo()
        {
            InitializeComponent();
            listViewDemo.ItemsSource = tListItem;            
            InitializeDatas();
        }

        private void InitializeDatas()
        {
            tListItem.Add(new itemDemo { ID = 1, Value = "Info001" });
            tListItem.Add(new itemDemo { ID = 4, Value = "InBB001" });
            tListItem.Add(new itemDemo { ID = 5, Value = "ISfo001" });
            tListItem.Add(new itemDemo { ID = 6, Value = "Info001" });
            tListItem.Add(new itemDemo { ID = 12, Value = "IAfo401" });
            tListItem.Add(new itemDemo { ID = 14, Value = "Info001" });
            tListItem.Add(new itemDemo { ID = 17, Value = "IZfo008" });
            tListItem.Add(new itemDemo { ID = 13, Value = "Cnfo00s" });
            tListItem.Add(new itemDemo { ID = 19, Value = "KnfoV01" });
        }

    }

    public class itemDemo : INotifyPropertyChanged
    {
        // 实现INotifyPropertyChanged接口
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private int _id;
        private string _value;

        public int ID { get => _id; set { _id = value; OnPropertyChanged(); } }
        
        public string Value { get => _value; set { _value = value; OnPropertyChanged(); } }
    }
}